<html>
<head><meta charset="utf-8"><title>Nested functions representation · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Nested.20functions.20representation.html">Nested functions representation</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="228307401"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Nested%20functions%20representation/near/228307401" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Nested.20functions.20representation.html#228307401">(Mar 01 2021 at 21:15)</a>:</h4>
<p>How are nested functions laid out in hir? Example</p>
<div class="codehilite"><pre><span></span><code>fn foo() {
  fn bar() {
  }
}
</code></pre></div>



<a name="228307471"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Nested%20functions%20representation/near/228307471" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Nested.20functions.20representation.html#228307471">(Mar 01 2021 at 21:16)</a>:</h4>
<p>Is <code>bar</code> it's own <code>Item</code>?</p>



<a name="228307494"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Nested%20functions%20representation/near/228307494" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Nested.20functions.20representation.html#228307494">(Mar 01 2021 at 21:16)</a>:</h4>
<p>Would <code>foo</code> be <code>bar</code>s <code>owner</code>?</p>



<a name="228308280"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Nested%20functions%20representation/near/228308280" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cjgillot <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Nested.20functions.20representation.html#228308280">(Mar 01 2021 at 21:21)</a>:</h4>
<p>bar is its own Item, and its own owner.</p>



<a name="228308292"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Nested%20functions%20representation/near/228308292" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cjgillot <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Nested.20functions.20representation.html#228308292">(Mar 01 2021 at 21:21)</a>:</h4>
<p>foo is bar's parent.</p>



<a name="228308500"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Nested%20functions%20representation/near/228308500" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cjgillot <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Nested.20functions.20representation.html#228308500">(Mar 01 2021 at 21:22)</a>:</h4>
<p>More generally, owners are: Item, TraitItem, ImplItem, ForeignItem, MacroDef, and the GenericParam from impl-trait desugaring.</p>



<a name="228308565"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Nested%20functions%20representation/near/228308565" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Nested.20functions.20representation.html#228308565">(Mar 01 2021 at 21:23)</a>:</h4>
<p>I think <code>get_parent_item</code> doesn't do what I think it does</p>



<a name="228308602"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Nested%20functions%20representation/near/228308602" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Nested.20functions.20representation.html#228308602">(Mar 01 2021 at 21:23)</a>:</h4>
<p>I was thinking parent == owner</p>



<a name="228308784"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Nested%20functions%20representation/near/228308784" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cjgillot <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Nested.20functions.20representation.html#228308784">(Mar 01 2021 at 21:25)</a>:</h4>
<p>parent allows to walk the HIR tree one node at a time. owner groups all the nodes inside the same Item.</p>



<a name="228308848"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Nested%20functions%20representation/near/228308848" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cjgillot <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Nested.20functions.20representation.html#228308848">(Mar 01 2021 at 21:25)</a>:</h4>
<p>All nodes have parents, except for the crate root.</p>



<a name="228308884"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Nested%20functions%20representation/near/228308884" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Nested.20functions.20representation.html#228308884">(Mar 01 2021 at 21:25)</a>:</h4>
<p>wait, so what is an owner?</p>



<a name="228308897"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Nested%20functions%20representation/near/228308897" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Nested.20functions.20representation.html#228308897">(Mar 01 2021 at 21:25)</a>:</h4>
<p>So, what's the recommended way to get the enclosing <code>Item</code> for a given <code>HirId</code></p>



<a name="228309082"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Nested%20functions%20representation/near/228309082" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cjgillot <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Nested.20functions.20representation.html#228309082">(Mar 01 2021 at 21:27)</a>:</h4>
<p><span class="user-mention" data-user-id="232957">@Jack Huey</span> it depends on what the HirId refers to. If it refers to a non-owner, get_parent_item and hir_id.owner should return pretty much the same information.</p>



<a name="228309115"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Nested%20functions%20representation/near/228309115" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Nested.20functions.20representation.html#228309115">(Mar 01 2021 at 21:27)</a>:</h4>
<p><span class="user-mention silent" data-user-id="248906">cjgillot</span> <a href="#narrow/stream/182449-t-compiler.2Fhelp/topic/Nested.20functions.20representation/near/228308784">said</a>:</p>
<blockquote>
<p>parent allows to walk the HIR tree one node at a time. owner groups all the nodes inside the same Item.</p>
</blockquote>
<p>Wait, so, would the <code>owner</code> of lifetimes across two different functions in an impl be the functions, or the impl?</p>



<a name="228309322"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Nested%20functions%20representation/near/228309322" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Nested.20functions.20representation.html#228309322">(Mar 01 2021 at 21:28)</a>:</h4>
<p>Let me take a step back and explain what I'm trying to do, because that might be more helpful.</p>



<a name="228309483"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Nested%20functions%20representation/near/228309483" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Nested.20functions.20representation.html#228309483">(Mar 01 2021 at 21:29)</a>:</h4>
<p>So, in <code>rustc_resolve::late::lifetimes</code>, the current <code>resolve_lifetimes</code> visits all the items in a crate. I'm trying to make it so that it does this <em>per Item</em></p>



<a name="228309741"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Nested%20functions%20representation/near/228309741" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cjgillot <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Nested.20functions.20representation.html#228309741">(Mar 01 2021 at 21:31)</a>:</h4>
<p><span class="user-mention silent" data-user-id="232545">Joshua Nelson</span> <a href="#narrow/stream/182449-t-compiler.2Fhelp/topic/Nested.20functions.20representation/near/228308884">said</a>:</p>
<blockquote>
<p>wait, so what is an owner?</p>
</blockquote>
<p>IIUC, owners correspond to HIR sub-trees must be typechecked and borrowchecked all at once. Typically, the list I gave you above. This does not always correspond to definitions (= stuff that has a DefId): closures are definitions, but must be typechecked with the enclosing scope, so are not owners.</p>



<a name="228309891"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Nested%20functions%20representation/near/228309891" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cjgillot <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Nested.20functions.20representation.html#228309891">(Mar 01 2021 at 21:32)</a>:</h4>
<p><span class="user-mention silent" data-user-id="232957">Jack Huey</span> <a href="#narrow/stream/182449-t-compiler.2Fhelp/topic/Nested.20functions.20representation/near/228309483">said</a>:</p>
<blockquote>
<p>So, in <code>rustc_resolve::late::lifetimes</code>, the current <code>resolve_lifetimes</code> visits all the items in a crate. I'm trying to make it so that it does this <em>per Item</em></p>
</blockquote>
<p>What do you mean /per item/?</p>



<a name="228309988"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Nested%20functions%20representation/near/228309988" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Nested.20functions.20representation.html#228309988">(Mar 01 2021 at 21:32)</a>:</h4>
<p><span class="user-mention silent" data-user-id="248906">cjgillot</span> <a href="#narrow/stream/182449-t-compiler.2Fhelp/topic/Nested.20functions.20representation/near/228309891">said</a>:</p>
<blockquote>
<p><span class="user-mention silent" data-user-id="232957">Jack Huey</span> <a href="#narrow/stream/182449-t-compiler.2Fhelp/topic/Nested.20functions.20representation/near/228309483">said</a>:</p>
<blockquote>
<p>So, in <code>rustc_resolve::late::lifetimes</code>, the current <code>resolve_lifetimes</code> visits all the items in a crate. I'm trying to make it so that it does this <em>per Item</em></p>
</blockquote>
<p>What do you mean /per item/?</p>
</blockquote>
<p>So, rather than <code>resolve_lifetimes</code> taking a <code>CrateNum</code>, it would take a <code>LocalDefId</code> of an Item</p>



<a name="228310232"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Nested%20functions%20representation/near/228310232" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Nested.20functions.20representation.html#228310232">(Mar 01 2021 at 21:34)</a>:</h4>
<p>Currently, for example, <code>named_region_map</code> takes a <code>LocalDefId</code> of an owner (of a lifetime), asks for the <code>ResolveLifetimes</code> of the entire crate, then returns a map for all the lifetimes of the owner</p>



<a name="228310412"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Nested%20functions%20representation/near/228310412" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Nested.20functions.20representation.html#228310412">(Mar 01 2021 at 21:35)</a>:</h4>
<p>I'm trying to change that to instead take a <code>LocalDefId</code> of an owner (of a lifetime), ask for the <code>ResolveLifetimes</code> the outermost <code>Item</code> containing that owner, and the return a map for all the lifetimes of the owner</p>



<a name="228310872"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Nested%20functions%20representation/near/228310872" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cjgillot <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Nested.20functions.20representation.html#228310872">(Mar 01 2021 at 21:38)</a>:</h4>
<p>I see.</p>



<a name="228310976"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Nested%20functions%20representation/near/228310976" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cjgillot <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Nested.20functions.20representation.html#228310976">(Mar 01 2021 at 21:39)</a>:</h4>
<p>What happens when you simply turn the loop on items in <code>rustc_resolve::late::lifetimes::krate</code> into just visiting the item whose LocalDefId you query?</p>



<a name="228311111"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Nested%20functions%20representation/near/228311111" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Nested.20functions.20representation.html#228311111">(Mar 01 2021 at 21:40)</a>:</h4>
<p>Well, I think the LocalDefId isn't always an Item. It could e.g. be a function on an impl</p>



<a name="228311116"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Nested%20functions%20representation/near/228311116" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cjgillot <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Nested.20functions.20representation.html#228311116">(Mar 01 2021 at 21:40)</a>:</h4>
<p><code>for item in krate.items.values()</code> =&gt; <code>if let Some(item) = krate.items.get(&amp;hir::ItemId { def_id: my_owner }</code>.</p>



<a name="228311200"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Nested%20functions%20representation/near/228311200" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cjgillot <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Nested.20functions.20representation.html#228311200">(Mar 01 2021 at 21:41)</a>:</h4>
<p>Yes, it's not always an Item, but <code>krate.items</code> is a BTreeMap you can query for.</p>



<a name="228311219"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Nested%20functions%20representation/near/228311219" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cjgillot <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Nested.20functions.20representation.html#228311219">(Mar 01 2021 at 21:41)</a>:</h4>
<p>Better: have your query take a hir::ItemId, so you know this is an Item.</p>



<a name="228311341"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Nested%20functions%20representation/near/228311341" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Nested.20functions.20representation.html#228311341">(Mar 01 2021 at 21:42)</a>:</h4>
<p>Hmm, but I still have to get the enclosing Item for a given lifetime</p>



<a name="228311408"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Nested%20functions%20representation/near/228311408" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cjgillot <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Nested.20functions.20representation.html#228311408">(Mar 01 2021 at 21:43)</a>:</h4>
<p>You mean for the query's caller?</p>



<a name="228311420"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Nested%20functions%20representation/near/228311420" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Nested.20functions.20representation.html#228311420">(Mar 01 2021 at 21:43)</a>:</h4>
<p>Yeah</p>



<a name="228311437"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Nested%20functions%20representation/near/228311437" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cjgillot <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Nested.20functions.20representation.html#228311437">(Mar 01 2021 at 21:43)</a>:</h4>
<p><code>get_parent_item</code> should do the trick.</p>



<a name="228311605"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Nested%20functions%20representation/near/228311605" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cjgillot <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Nested.20functions.20representation.html#228311605">(Mar 01 2021 at 21:45)</a>:</h4>
<p>You may need to verify is actually points to an Item, and not to Crate, ImplItem, TraitItem or ForeignItem.</p>



<a name="228311824"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Nested%20functions%20representation/near/228311824" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Nested.20functions.20representation.html#228311824">(Mar 01 2021 at 21:46)</a>:</h4>
<p>Maybe I need to rearrange things. I was sort of expecting the named_region_map  query to still return a map. But then I have to check if the passed is an item or not</p>



<a name="228312006"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Nested%20functions%20representation/near/228312006" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cjgillot <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Nested.20functions.20representation.html#228312006">(Mar 01 2021 at 21:47)</a>:</h4>
<p>I think you can do it without changing named_region_map's interface.</p>



<a name="228312218"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Nested%20functions%20representation/near/228312218" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Nested.20functions.20representation.html#228312218">(Mar 01 2021 at 21:49)</a>:</h4>
<p>So, here's what I have currently:</p>



<a name="228312230"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Nested%20functions%20representation/near/228312230" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Nested.20functions.20representation.html#228312230">(Mar 01 2021 at 21:49)</a>:</h4>
<p><code>named_region_map: |tcx, id| tcx.resolve_lifetime_for_hir_id(item_for(tcx, id)).defs.get(&amp;id),</code></p>



<a name="228312252"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Nested%20functions%20representation/near/228312252" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Nested.20functions.20representation.html#228312252">(Mar 01 2021 at 21:49)</a>:</h4>
<div class="codehilite"><pre><span></span><code>fn item_for(tcx: TyCtxt&lt;&#39;_&gt;, local_def_id: LocalDefId) -&gt; LocalDefId {
    let hir_id = tcx.hir().local_def_id_to_hir_id(local_def_id);
    match tcx.hir().find(hir_id) {
        Some(Node::Item(item)) =&gt; {
            return item.def_id;
        },
        _ =&gt; {},
    }
    let item = {
        let hir = tcx.hir();
        let mut parent_iter = hir.parent_iter(hir_id);
        loop {
            let node = parent_iter.next().map(|n| n.1);
            match node {
                Some(hir::Node::Item(item)) =&gt; {
                    break item.def_id
                },
                Some(hir::Node::Crate(_)) | None =&gt; bug!(&quot;Called `item_for` on an Item.&quot;),
                _ =&gt; {}
            }
        }
    };
    item
}
</code></pre></div>



<a name="228312485"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Nested%20functions%20representation/near/228312485" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Nested.20functions.20representation.html#228312485">(Mar 01 2021 at 21:51)</a>:</h4>
<p>And the <code>resolve_lifetime_for_hir_id</code> basically just returns something like <code>FxHashMap&lt;LocalDefId, FxHashMap&lt;ItemLocalId, Region&gt;&gt;</code></p>



<a name="228312494"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Nested%20functions%20representation/near/228312494" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cjgillot <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Nested.20functions.20representation.html#228312494">(Mar 01 2021 at 21:51)</a>:</h4>
<p>You should be able to replace <code>item_for(tcx, id)</code> by just <code>id</code>.</p>



<a name="228312632"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Nested%20functions%20representation/near/228312632" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Nested.20functions.20representation.html#228312632">(Mar 01 2021 at 21:52)</a>:</h4>
<p>But we won't always get an <code>Item</code>?</p>



<a name="228312662"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Nested%20functions%20representation/near/228312662" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Nested.20functions.20representation.html#228312662">(Mar 01 2021 at 21:52)</a>:</h4>
<p>Sometimes it would be e.g. an <code>ImplItem</code></p>



<a name="228312720"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Nested%20functions%20representation/near/228312720" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cjgillot <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Nested.20functions.20representation.html#228312720">(Mar 01 2021 at 21:53)</a>:</h4>
<p>Then you can return an empty map?</p>



<a name="228312832"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Nested%20functions%20representation/near/228312832" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Nested.20functions.20representation.html#228312832">(Mar 01 2021 at 21:53)</a>:</h4>
<p>No, I still need to return the map for the owner passed in</p>



<a name="228312934"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Nested%20functions%20representation/near/228312934" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Nested.20functions.20representation.html#228312934">(Mar 01 2021 at 21:54)</a>:</h4>
<p>But I have to run <code>resolve_lifetime_for_hir_id</code> on a whole <code>Item</code></p>



<a name="228313041"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Nested%20functions%20representation/near/228313041" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Nested.20functions.20representation.html#228313041">(Mar 01 2021 at 21:55)</a>:</h4>
<p>For more reference, this exists on <code>ty/context</code>:</p>
<div class="codehilite"><pre><span></span><code>    pub fn named_region(self, id: HirId) -&gt; Option&lt;resolve_lifetime::Region&gt; {
        self.named_region_map(id.owner).and_then(|map| map.get(&amp;id.local_id).cloned())
    }
</code></pre></div>



<a name="228313186"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Nested%20functions%20representation/near/228313186" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cjgillot <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Nested.20functions.20representation.html#228313186">(Mar 01 2021 at 21:56)</a>:</h4>
<p>Reading the code with more attention, I am starting to understand you need.</p>



<a name="228313234"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Nested%20functions%20representation/near/228313234" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Nested.20functions.20representation.html#228313234">(Mar 01 2021 at 21:56)</a>:</h4>
<p>(Btw thank you for your help)</p>



<a name="228313289"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Nested%20functions%20representation/near/228313289" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cjgillot <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Nested.20functions.20representation.html#228313289">(Mar 01 2021 at 21:57)</a>:</h4>
<p>Your <code>item_for</code> should work. Do you have a test failure?</p>



<a name="228313384"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Nested%20functions%20representation/near/228313384" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Nested.20functions.20representation.html#228313384">(Mar 01 2021 at 21:57)</a>:</h4>
<p>Well, it can't compile <code>core</code></p>



<a name="228313392"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Nested%20functions%20representation/near/228313392" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Nested.20functions.20representation.html#228313392">(Mar 01 2021 at 21:57)</a>:</h4>
<div class="codehilite"><pre><span></span><code>error: lifetime may not live long enough
    --&gt; library/core/src/iter/traits/iterator.rs:3334:13
     |
3330 |           fn check&lt;&#39;a, T&gt;(
     |                    -- lifetime `&#39;a` defined here
...
3334 | /             move |curr| {
3335 | |                 if let Some(Ordering::Greater) | None = compare(&amp;last, &amp;curr) {
3336 | |                     return false;
3337 | |                 }
3338 | |                 *last = curr;
3339 | |                 true
3340 | |             }
     | |_____________^ returning this value requires that `&#39;a` must outlive `&#39;static`
     |
     = help: consider replacing `&#39;a` with `&#39;static`
     = help: consider replacing `&#39;a` with `&#39;static`
</code></pre></div>



<a name="228313412"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Nested%20functions%20representation/near/228313412" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Nested.20functions.20representation.html#228313412">(Mar 01 2021 at 21:58)</a>:</h4>
<p>It's possible it's unrelated</p>



<a name="228313505"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Nested%20functions%20representation/near/228313505" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Nested.20functions.20representation.html#228313505">(Mar 01 2021 at 21:58)</a>:</h4>
<p>(there's a lot more errors like that)</p>



<a name="228313563"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Nested%20functions%20representation/near/228313563" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cjgillot <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Nested.20functions.20representation.html#228313563">(Mar 01 2021 at 21:59)</a>:</h4>
<p>Definitely related :)</p>



<a name="228313621"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Nested%20functions%20representation/near/228313621" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Nested.20functions.20representation.html#228313621">(Mar 01 2021 at 21:59)</a>:</h4>
<p>But essentially, I <em>think</em> what's happening is somewhere is asking for the <code>Region</code> of a <code>HirId</code>, it can't find it in a map, and it's falling back to <code>Static</code></p>



<a name="228313944"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Nested%20functions%20representation/near/228313944" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cjgillot <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Nested.20functions.20representation.html#228313944">(Mar 01 2021 at 22:01)</a>:</h4>
<p>The tricky part is probably the presence of a return-position impl-trait.</p>



<a name="228314010"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Nested%20functions%20representation/near/228314010" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cjgillot <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Nested.20functions.20representation.html#228314010">(Mar 01 2021 at 22:01)</a>:</h4>
<p>Resolve works on parameters, so it understands that last has lifetime 'a.</p>



<a name="228314164"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Nested%20functions%20representation/near/228314164" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cjgillot <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Nested.20functions.20representation.html#228314164">(Mar 01 2021 at 22:02)</a>:</h4>
<p>But impl-traits are a subtle pile of hacks. It may fail to find the 'a in the return type, and interpret it as a brand-new lifetime.</p>



<a name="228314198"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Nested%20functions%20representation/near/228314198" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cjgillot <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Nested.20functions.20representation.html#228314198">(Mar 01 2021 at 22:02)</a>:</h4>
<p>(Speculating wildly here).</p>



<a name="228314233"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Nested%20functions%20representation/near/228314233" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Nested.20functions.20representation.html#228314233">(Mar 01 2021 at 22:02)</a>:</h4>
<p>That sounds reasonable</p>



<a name="228314479"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Nested%20functions%20representation/near/228314479" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Nested.20functions.20representation.html#228314479">(Mar 01 2021 at 22:04)</a>:</h4>
<p>Hmm. Yeah, I wonder if the impl trait desugaring interferes with this</p>



<a name="228315541"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Nested%20functions%20representation/near/228315541" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cjgillot <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Nested.20functions.20representation.html#228315541">(Mar 01 2021 at 22:11)</a>:</h4>
<p>Do you have failures that are not impl-traits?</p>



<a name="228315567"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Nested%20functions%20representation/near/228315567" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Nested.20functions.20representation.html#228315567">(Mar 01 2021 at 22:12)</a>:</h4>
<p>let me look</p>



<a name="228315871"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Nested%20functions%20representation/near/228315871" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Nested.20functions.20representation.html#228315871">(Mar 01 2021 at 22:14)</a>:</h4>
<p>I just overwrote the log so have to rebuild</p>



<a name="228315983"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Nested%20functions%20representation/near/228315983" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cjgillot <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Nested.20functions.20representation.html#228315983">(Mar 01 2021 at 22:14)</a>:</h4>
<p>Typical rustc dev workflow <span aria-label="big smile" class="emoji emoji-1f604" role="img" title="big smile">:big_smile:</span></p>



<a name="228316237"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Nested%20functions%20representation/near/228316237" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Nested.20functions.20representation.html#228316237">(Mar 01 2021 at 22:15)</a>:</h4>
<p>from what I remember, I think many were impl-traits</p>



<a name="228316340"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Nested%20functions%20representation/near/228316340" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Nested.20functions.20representation.html#228316340">(Mar 01 2021 at 22:15)</a>:</h4>
<p>and honestly, that does make sense to me, at least I could see why that might be what's wrong</p>



<a name="228316462"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Nested%20functions%20representation/near/228316462" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Nested.20functions.20representation.html#228316462">(Mar 01 2021 at 22:16)</a>:</h4>
<p>I was just assuming I messed something up in terms of getting the proper <code>Item</code> and such</p>



<a name="228316812"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Nested%20functions%20representation/near/228316812" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Nested.20functions.20representation.html#228316812">(Mar 01 2021 at 22:19)</a>:</h4>
<p><code>let def = self.map.defs.get(&amp;lifetime.hir_id).cloned();</code> I bet that's the problem line though</p>



<a name="228316915"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Nested%20functions%20representation/near/228316915" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Nested.20functions.20representation.html#228316915">(Mar 01 2021 at 22:20)</a>:</h4>
<p>That needs to be a query probably</p>



<a name="228317242"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Nested%20functions%20representation/near/228317242" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Nested.20functions.20representation.html#228317242">(Mar 01 2021 at 22:22)</a>:</h4>
<p>err, no</p>



<a name="228318090"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Nested%20functions%20representation/near/228318090" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Nested.20functions.20representation.html#228318090">(Mar 01 2021 at 22:28)</a>:</h4>
<p>Okay, so, of the 10 or so that I've looked at</p>



<a name="228318100"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Nested%20functions%20representation/near/228318100" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Nested.20functions.20representation.html#228318100">(Mar 01 2021 at 22:28)</a>:</h4>
<p>All are impl trait</p>



<a name="228318166"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Nested%20functions%20representation/near/228318166" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Nested.20functions.20representation.html#228318166">(Mar 01 2021 at 22:29)</a>:</h4>
<p>Which is good information</p>



<a name="228318372"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Nested%20functions%20representation/near/228318372" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cjgillot <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Nested.20functions.20representation.html#228318372">(Mar 01 2021 at 22:30)</a>:</h4>
<p>All return impl-trait, or also parameter impl-trait?</p>



<a name="228318413"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Nested%20functions%20representation/near/228318413" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Nested.20functions.20representation.html#228318413">(Mar 01 2021 at 22:30)</a>:</h4>
<p>I think only return impl trait</p>



<a name="228318488"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Nested%20functions%20representation/near/228318488" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Nested.20functions.20representation.html#228318488">(Mar 01 2021 at 22:31)</a>:</h4>
<p>But I'm not sure how many examples of parameter impl-trait there <em>are</em></p>



<a name="228319390"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Nested%20functions%20representation/near/228319390" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Nested.20functions.20representation.html#228319390">(Mar 01 2021 at 22:38)</a>:</h4>
<p>Ah yeah, the error for <code>filter_try_fold</code> tells me this has nothing to do with the nested functions, because it doesn't have one <span aria-label="joy" class="emoji emoji-1f602" role="img" title="joy">:joy:</span></p>



<a name="228319496"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Nested%20functions%20representation/near/228319496" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cjgillot <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Nested.20functions.20representation.html#228319496">(Mar 01 2021 at 22:39)</a>:</h4>
<p>return impl-trait are desugared inside rustc_ast_lowering::lower_opaque_impl_trait. This function synthetises a new item as an OpaqueTy. The lifetime declarations are duplicated to define this item. It is then used with the lifetime arguments substituted.<br>
<code>fn foo&lt;'a&gt;() -&gt; impl Clone + 'a {}</code> becomes <code>fn foo&lt;'a&gt;() -&gt; Blah&lt;'a&gt; {}; type Blah&lt;'a&gt;: Clone;</code></p>



<a name="228319554"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Nested%20functions%20representation/near/228319554" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cjgillot <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Nested.20functions.20representation.html#228319554">(Mar 01 2021 at 22:39)</a>:</h4>
<p>With both <code>&lt;'a&gt;</code> coming from the same AST fragments.</p>



<a name="228319752"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Nested%20functions%20representation/near/228319752" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Nested.20functions.20representation.html#228319752">(Mar 01 2021 at 22:40)</a>:</h4>
<p>Yeah, I bet in one case or the other, it just can't find <code>'a</code> anymore</p>



<a name="228319854"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Nested%20functions%20representation/near/228319854" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Nested.20functions.20representation.html#228319854">(Mar 01 2021 at 22:41)</a>:</h4>
<p>But looks like we only visit both when we see <code>impl Clone + 'a</code></p>



<a name="228321063"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Nested%20functions%20representation/near/228321063" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cjgillot <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Nested.20functions.20representation.html#228321063">(Mar 01 2021 at 22:51)</a>:</h4>
<p>There is a special impl-trait block in LifetimeContext::visit_ty. Instrumenting it may be your best option here.</p>



<a name="228321299"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Nested%20functions%20representation/near/228321299" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Nested.20functions.20representation.html#228321299">(Mar 01 2021 at 22:53)</a>:</h4>
<p>Yes, I'm combing through <code>debug</code> output</p>



<a name="228322667"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Nested%20functions%20representation/near/228322667" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Nested.20functions.20representation.html#228322667">(Mar 01 2021 at 23:04)</a>:</h4>
<p>Gosh I love <code>#![no_core]</code> minimizations, so I don't have to compile <code>core</code>: <a href="https://gist.github.com/jackh726/732c62bbdbe529bef675341cab1b4746">https://gist.github.com/jackh726/732c62bbdbe529bef675341cab1b4746</a></p>



<a name="228322685"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Nested%20functions%20representation/near/228322685" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Nested.20functions.20representation.html#228322685">(Mar 01 2021 at 23:05)</a>:</h4>
<p>compiles fine with nightly, <code>unelided lifetime in signature</code> locally</p>



<a name="228322726"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Nested%20functions%20representation/near/228322726" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Nested.20functions.20representation.html#228322726">(Mar 01 2021 at 23:05)</a>:</h4>
<p>And that falls back to <code>'static</code></p>



<a name="228322742"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Nested%20functions%20representation/near/228322742" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Nested.20functions.20representation.html#228322742">(Mar 01 2021 at 23:05)</a>:</h4>
<p>So, that's where static is coming from</p>



<a name="228327361"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Nested%20functions%20representation/near/228327361" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Nested.20functions.20representation.html#228327361">(Mar 01 2021 at 23:43)</a>:</h4>
<p>Yeah, okay, so we're asking for <code>lifetime(HirId { owner: DefId(0:4 ~ min[317d]::foo::{opaque#0}), local_id: 6 }: 'a)</code>, but we resolve that under the <code>DefId(0:2 ~ min[317d]::foo)</code> Item</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>